#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int n, c;
LL a[N];
int main()
{
    cin >> n >> c;
    for(int i = 1; i <= n; i++) cin >> a[i];

    sort(a + 1, a + 1 + n);
    
    LL ret = 0;
    for(int i = 2; i <= n; i++)
    {
        // a[i]
        LL b = a[i] - c;
        ret += upper_bound(a + 1, a + i, b) - lower_bound(a + 1, a + i, b);
    }

    cout << ret << endl;
    return 0;
}
